
var sign=false;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    signonbg: getApp().globalData.source + "sign_in/sign-on-bg.png",
    info:[],
    signonshow: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getdetails()
    this.checkIsSignOn()
  },
  
  //判断是否签到
  checkIsSignOn: function () {
    if(sign){
      return
    }
    sign=true;
    var iphone = wx.getStorageSync("iPhone");
    if (iphone != "-1") {
      return
    }
    var vm = this
    var data = {
      userId: wx.getStorageSync("userId")
    };
    getApp().request(getApp().globalData.https + "activityResource/currentDaySignIn",
      "get", data,
      function (res) {
        if (res.code == 0) {
          if (res.data.currentDaySignIn == "0") {
            vm.getSignInfo()
          } else {
            vm.setData({
              signonshow: false
            })
          }

        }
      },
      function (res) { }
    )
  },


  //本周签到情况
  getSignInfo: function () {
    var vm = this
    var data = {
      userId: wx.getStorageSync("userId"),
      flg: "0"
    };
    getApp().request(getApp().globalData.https + "activityResource/signInList",
      "get", data,
      function (res) {
        if (res.code == 0) {
          var signinfo = res.data[0].subSignInBo;
          vm.setData({
            signonshow: true,
            signtop: signinfo,
          })

        }
      },
      function (res) { }
    )
  },
  signover: function () {
    this.setData({
      signonshow: false
    })
  },
  //点击签到
  sign_today: function () {
    var vm = this
    var data = {
      userId: wx.getStorageSync("userId"),
    };
    getApp().request(getApp().globalData.https + "activityResource/signInRecord",
      "get", data,
      function (res) {
        if (res.code == 0) {
          //签到提醒
          // vm.getSignInfo();
          getApp().showMsgToast('送您' + res.data.balance + "听币");
          vm.setData({
            signonshow: false,
          })
          vm.getdetails()
        } else {
          getApp().showMsgToast("已签到");
        }
      },
      function (res) { }
    )
  },
  //获取关注天天必听公账号h5地址
  getuserinfo: function () {
    var vm = this
    var data = {
      userId: wx.getStorageSync("userId")
    }
    getApp().requestLoading(getApp().globalData.https + "userResource/userDetailInfo",
      "get", data, "加载中..",
      function (res) {
        if (res.code == 0) {
          vm.setData({
            infodata: res.data
          })
        }
      },
      function (res) { });
  },

  todetails: function () {
    wx.navigateTo({
      url: '/pages/transaction_record/transaction_record',
    })
  },
  /**
   * 获取收听历史记录详情
   */
  getdetails: function () {
    var vm=this
    var data={
      userId:wx.getStorageSync("userId"),
      flg: "1"
    }
    getApp().request(getApp().globalData.https + "activityResource/signInList",
      "get", data,
      function (res) {
        if (res.code == 0) {
          vm.setData({
            info: res.data
          })
        }
      },
      function (res) {
       
      });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getuserinfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})